package com.sam.im.heiqun.uis.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.WalletDetailsEntity;
import com.yuyh.library.utils.TimeUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by houhuiosam on 2017/1/16.
 */

public class WalletDetailsAdatper extends BaseAdapter {

    private static final String TAG = WalletDetailsAdatper.class.getSimpleName();
    private List<WalletDetailsEntity> data;
    private LayoutInflater inflater;
    private Context mContext;

    public WalletDetailsAdatper(List<WalletDetailsEntity> data, Context context) {
        if (data == null)
            data = new ArrayList<>();
        this.data = new ArrayList<>();
        int size = data.size();
        for (int i = 0; i < size; i++) {
            this.data.add(0, data.get(i));
        }
        this.inflater = LayoutInflater.from(context);
        mContext = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public WalletDetailsEntity getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_wallet_details, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        WalletDetailsEntity entity = getItem(position);
        String time = TimeUtil.getAllTime(Long.valueOf(entity.getOccurTime()));
        holder.time.setText(time);

        if (entity.getMoneyDirect().equals("1")) {
            holder.money.setText("+" + entity.getAmount());
            holder.money.setTextColor(parent.getContext().getResources().getColor(R.color.headgreen));
        } else {
            holder.money.setText("-" + entity.getAmount());
            holder.money.setTextColor(parent.getContext().getResources().getColor(R.color.black));
        }

        String content = entity.getContent();
        switch (Integer.valueOf(entity.getMoneyType())) {
            case 1:
                holder.moneyType.setText(R.string.recharge);
                break;
            case 2:
                holder.moneyType.setText(R.string.withdraw);
                break;
            case 3:
                holder.moneyType.setText(R.string.send_red_package);
                break;
            case 4:
                holder.moneyType.setText(mContext.getString(R.string.from) + " " + content + " " + mContext.getString(R.string.de_red_package));
                break;
            case 5:
                String text = mContext.getString(R.string.transfer_to) + " " + content;
                holder.moneyType.setText(text);
                break;
            case 6:
                holder.moneyType.setText(content + " " + mContext.getString(R.string.transfer_to_you));
                break;
            case 7:
                holder.moneyType.setText(R.string.red_package_back);
                break;
            case 8:
                holder.moneyType.setText(R.string.transfer_back);
                break;
            case 10://AA收款
                holder.moneyType.setText(R.string.aa_get_money);
                break;
            case 11://AA付款
                holder.moneyType.setText(R.string.aa_pay_money);
                break;
            case 12://AA付款
                holder.moneyType.setText("购买群组等级");
                break;
            case 13://AA付款
                holder.moneyType.setText("付费加群");
                break;
            case 14://AA付款
                holder.moneyType.setText("群组续费");
                break;
        }

        return convertView;
    }

    private class ViewHolder {
        TextView moneyType;
        TextView time;
        TextView money;

        public ViewHolder(View itemView) {
            this.moneyType = (TextView) itemView.findViewById(R.id.money_type);
            this.time = (TextView) itemView.findViewById(R.id.time);
            this.money = (TextView) itemView.findViewById(R.id.money);
        }
    }
}
